<?php

namespace app\model;

use think\facade\Db;
use app\model\setting\LIMIT;

class ReaderModel extends \think\Model
{
    protected $table = "读者";
    protected $pk = "readerId";

    public function insertReaders($readers): int
    {
        //初始化密码
        foreach ($readers as $key => $value){
            //dump($value);
            $readers[$key]['password'] = "123456";
        }
        return $this->limit(LIMIT::$LIMITFORSQL)->insertAll($readers);
    }

    public function deleteReaders($ids)
    {
        return self::destroy($ids);
    }

    public function getThisReaderById($userName, $password)
    {
        return self::where("PASSWORD", $password)->find($userName);
    }

    public function updateReaders($readers)
    {
        //更新每一个读者
        foreach ($readers as $key => $value)
            self::update($value);// == "";
    }

}